import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import {  HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';
import {Service} from '../../../server/server';
import {InitService} from '../../../public/serve/init/init.service';
import {DatePipe} from '@angular/common';
import {CudTableService} from '../../../public/serve/cud-table/cud-table.service';
import {HintsService} from '../../../public/serve/hints/hints.service';
import { themeTableTagAddtype } from '../themetable-tag.data'

declare var $: any;

interface themeTableTagAddResponse {
    result: string[];
    result_code: string;
    message: string;
}

@Component({
  selector: 'app-themetable-tag-add',
  templateUrl: './themetable-tag-add.component.html',
})

export class ThemetableTagAddComponent implements OnInit {
  constructor(private hintsService: HintsService,private http: HttpClient, private router: Router, private server:Service,public initService: InitService, private datePipe: DatePipe, private tableListService: CudTableService) {
  }

  @Output()
  addOutput: EventEmitter<any> = new EventEmitter();
  //清空
  @ViewChild('addForm') formElement: HTMLFormElement;
  public parentList : any;
  @Input() details: any;

  reset() {
    this.initService._init();
    $("#add").modal("hide");
    // this.formElement.reset();
    setTimeout(() => {
      this.default();
    }, 300);
  }

  //默认数据
  default() {
    this.themeTableTagAdd.labelName = '';
    this.themeTableTagAdd.createBy = '';
    this.themeTableTagAdd.createTime = '';
  }

  _showAddChildInfo(){
    this.details = '';
  }

  //datatype
  themeTableTagAdd: themeTableTagAddtype = {
      labelId: '',
      labelName: '',
      createTime: '',
      createBy: ''
  };

  //用户id
  createUserId: any;

  ngOnInit() {

  }


    //add
    add(v): void {
        let body = {
            createBy: this.server.getuserName(),
            labelName: this.themeTableTagAdd.labelName,
        };

        this.http.post<themeTableTagAddResponse>(this.server.baseUrl + 'Service/ThemeWords/addThemeTableLabel', body)
            .subscribe(res => {
                this.addOutput.emit(res.result_code);
                this._showAddChildInfo();
                //console.log(res)
                if (res.result_code === '0000') {
                    this.reset();
                }
                this.hintsService.messages(res.message, res.result_code);
            })
    }

}
